<template>
	<view  style="display: flex;flex-direction: column; width: 749rpx;font-size: 25rpx;">
		<view style="display: flex;width: 90%;justify-content: space-around;margin: 0 auto;padding: 5rpx;">
			<view  @click="baoxinke" style="display: flex;background-color: blue;color: white;padding:5rpx 15rpx;align-items: center;justify-content: center;border-radius: 15rpx; ">
				报新课
			</view>
			<view v-if="!infor.isxufei" @click="xufei" style="display: flex;background-color: blue;color: white;padding:5rpx 15rpx;align-items: center;justify-content: center;border-radius: 15rpx; ">
				续费
			</view>
			<view @click="xiugai" v-if="meiyi_userinfo.permission.indexOf('update_student')!=-1 && infor.zhuangtai!=0 && infor.zhuangtai!=3" style="display: flex;background-color: blue;color: white;padding:5rpx 15rpx;align-items: center;justify-content: center;border-radius: 15rpx; ">
				修改
			</view>
			<view  @click="tiaoban" v-if="meiyi_userinfo.permission.indexOf('tiaoban')!=-1 && infor.zhuangtai!=0 && infor.zhuangtai!=3" style="display: flex;background-color: blue;color: white;padding:5rpx 15rpx;align-items: center;justify-content: center;border-radius: 15rpx; ">
				调班
			</view>
			<view v-if="meiyi_userinfo.permission.indexOf('tuifei')!=-1 && infor.zhuangtai!=0 && infor.zhuangtai!=3 " @click="tuifei" style="display: flex;background-color: blue;color: white;padding:5rpx 15rpx;align-items: center;justify-content: center;border-radius: 15rpx; ">
				退费
			</view>
		</view>
		<view style="display: flex;width: 650rpx;font-size: 25rpx; border-radius: 20rpx; flex-wrap: wrap; margin: 25rpx auto 0 auto; padding: 0rpx 30rpx 25rpx 30rpx;box-shadow: 1px 1px 5px #c2c2c2; justify-content: space-between;">
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">姓名：</text>{{infor1.name}}
			</view>
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">年龄：</text>{{infor1.age}}岁
			</view>
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">课程：</text>{{infor.kecheng}}
			</view>		
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">校区：</text>{{infor.xiaoqu}}
			</view>		
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">电话：</text>{{infor1.mobile}}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">住址：</text>{{infor1.zhuzhi}}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">学校：</text>{{infor1.school}}
			</view>
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">年级：</text>{{infor1.nianji}}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">报名日期：</text>{{infor.baomingdate}}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">到期日期：</text>{{infor.jiezhidate}}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">费用：</text>{{infor.money1}}元
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">课程数量：</text>{{infor.kechengshu}}节
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">核销数量：</text>{{shu4!==0?shu4:infor.yihexiaoshu}}节
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">单节课费用：</text>{{ infor.yikefeiyong }}元
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">续费：</text>{{infor.isxufei?"有续费":"无续费" }}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">备注：</text>{{infor.beizhu }}
			</view>	
			<view style="margin-top: 20rpx;">
				<text style="color: black;font-weight: 700;">录单：</text>{{infor.riqi }}
			</view>	
		</view>
		<!-- 横线隔开 -->
		<!-- <view style="display: flex;width: 90%;background-color: #DFDFDF;height: 3rpx;margin: 10rpx auto;"></view>	 -->
		<view style="display: flex;flex-flow: row;align-items: center;margin-top: 20rpx;">
			<view style="display: flex;width:8rpx;height: 29rpx;background-color: blue;border-radius: 10rpx;margin:10rpx 10rpx 10rpx 50rpx;"></view>
			<view class="">
				销课记录
			</view>
			<view v-if="meiyi_userinfo.permission.indexOf('del_xiaokelist')!=-1" style="display: flex;padding:5rpx 20rpx;background-color: blue;border-radius: 15rpx;margin-left: 30rpx;color: white;font-size: 25rpx;" @click="shanchu">
				{{shu3}}
			</view>
		</view>
		<view style="display: flex;width:700rpx;margin: 0 auto;justify-content: space-around;">
			<view class="">
				序号
			</view>
			<view class="">
				销课时间
			</view>
			<view class="">
				总销课数
			</view>
		</view>
		<view v-for="(item, index) in shu2"  :key="index" :title="item.name" style="display: flex;margin: 10rpx auto; background-color: white;border-radius: 20rpx;box-shadow: 1px 1px 5px #c2c2c2;width:680rpx;justify-content: space-around;flex-direction: column;">
			<view  style="display: flex;width:650rpx;align-items: center;margin: 15rpx 0 15rpx 30rpx;">
				<view style="display: flex;flex: 1; align-items: center;" @click="yulan(item)">
					<image style="width:40rpx;height:40rpx;" src="../../static/zhaopian.png" mode=""></image>
					{{shu1-index}}
				</view>
				<view style="display: flex;flex:4;justify-content: center;">
					{{item.xiaoketime}}
				</view>
				<view style="display: flex;flex: 1;">
					{{item.yihexiaoshu}}
				</view>
				<view v-if="show1" @click="shanchu1(item,shu1-index)"  style="display: flex;background-color:blue;color: white;width:50rpx;height: 50rpx; border-radius: 15rpx;align-items: center;box-shadow: 1px 1px 5px #c2c2c2;justify-content: center;margin: 0 10rpx 0 30rpx;">
					<uni-icons style="font-size: 45rpx;color: white;" type="close"></uni-icons>
				</view>
			</view>
			<view v-if="item.beizhu" style="display: flex;font-size: 25rpx;color: darkgrey;margin-left: 30rpx;">
				备注：{{item.beizhu}}
			</view>
			
		</view>
		<uni-popup ref="popup" type="center">
			<view style="display: flex;width: 650rpx; border-radius: 15rpx;background-color: white;flex-direction: column;">
				<view style="display: flex;width: 600rpx;margin: 60rpx auto 20rpx auto;flex-direction: column;">
					退费原因：
					<uni-easyinput style="margin: 10rpx auto 20rpx auto;" type="textarea" v-model="tuifeiyuanyin" placeholder="请输入退费的原因" />
					退费金额：
					<uni-easyinput  style="margin: 10rpx auto 40rpx auto;" type="number" v-model="tuifeijine" placeholder="请输入退费的金额" />
				</view>
			
				<view style="display: flex;width: 80%;margin: 30rpx auto 60rpx auto;justify-content: space-around;">
					<view  @click="$refs.popup.close()" style="display: flex;justify-content: center;border-radius: 15rpx; align-items: center;padding: 15rpx 25rpx;background-color: coral;color: white;">
						取消
					</view>
					<view @click="tuifei1" style="display: flex;justify-content: center;margin-left: 30rpx; border-radius: 15rpx; align-items: center;padding: 15rpx 25rpx;background-color: blue;color: white;">
						确定
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import getDateTime from '@/common/getdateTime.js';
	// import toast from '../../uni_modules/uview-ui/libs/config/props/toast';
	export default {
		data() {
			return {
				tuifeiyuanyin:'',
				tuifeijine:'',
				shu1:0,//销课明细的条数
				shu2:[],//查找本人销课的数据
				shu3:'管理',
				shu4:0,
				shu6:'',//学生的校区
				show1:false,//删除符号的显示
				meiyi_userinfo:{
					permission:[]
				},
				infor:[],
				infor1:[]
			}
		},
		async onLoad() {
			let meiyi_name_tel=await uni.getStorageSync('meiyi_name_tel')
			this.jingshouren=meiyi_name_tel.name+meiyi_name_tel.mobile
			this.meiyi_userinfo=await uniCloud.getCurrentUserInfo()
			this.infor=await uni.getStorageSync('aoyashenginfor')
			this.infor1=this.infor.id[0]
			console.log('55',this.infor);
			this.xiaokelist(this.infor._id)
		},
		methods: {
			yulan(e){
				if ('xiaokepic' in e){
					let urls=[]
					urls.push(e.xiaokepic)
					uni.previewImage({
						urls: urls,
						// current: index
					});
				}else{
					uni.showToast({
						title:'本条数据未录入照片信息！',
						icon:'none',
						duration:3000
					})
				}
				
			},
			tuifei(){
				this.$refs.popup.open()
			},
			tuifei1(){
				if(!this.tuifeiyuanyin || !this.tuifeijine){
					uni.showToast({
						title:'退费原因和金额都需填写！',
						icon:'none',
						duration:3000
					})
				}
				this.$refs.popup.close()
				uni.showLoading({
					title: '退费中...',
					mask: true
				})
				//把baokelist改为状态3
				//zhangwuliushui中添加一条记录
				//tuifeilist中添加一条信息
				//xiugaishuju中添加一条信息
				uniCloud.callFunction({
					name:"weifun",
					data:{
						leixing:6,//类型为5时，调出这个学生的销课记录
						id:this.infor._id,
						jine:parseFloat(this.tuifeijine),
						infor:this.infor,
						tuifeiyuanyin:this.tuifeiyuanyin,
						riqi:getDateTime.dateTimeStr('y-m-d h:i:s'),
						jingshouren:this.jingshouren
					}
				}).then(res=>{
					uni.hideLoading()
					uni.showToast({
						title:'退费完成',
						icon:'none',
						duration:3000
					})
					uni.navigateTo({
						url: '/pages/xueshenginfor/xueshenginfor'
					})
				})
			},
			baoxinke(){
				uni.navigateTo({
						url: "/pages/baoxinke/baoxinke"
				})
			},
			tiaoban(){
				uni.navigateTo({
						url: "/pages/tiaoban/tiaoban"
				})
			},
			xufei(){
				uni.navigateTo({
						url: "/pages/xufei/xufei"
				})
			},
			xiugai(){
				uni.navigateTo({
						url: "/pages/xueshengluru/xueshengluru?ip=1"
				})
			},
			//删除符号
			shanchu(){
				if(this.show1==false){
					this.show1=true
					this.shu3='完成'
				}else{
					this.show1=false
					this.shu3='管理'
				}
			},
			// 删除销课记录
			shanchu1(e,index){
				uni.showModal({
					title: '重要提示，删除第'+index+'条数据',
					content: '再次确认，一定要删除吗？再次确认，一定要删除吗？再次确认，一定要删除吗？再次确认，一定要删除吗？再次确认，一定要删除吗？再次确认，一定要删除吗？',
					showCancel: true,
					cancelText: '取消',
					confirmText: '确定',
					success: res => {
						if (res.confirm) {
							uni.showLoading({
								title: '删除中...',
								mask: true
							});
							//一、xiaokelist中删除本条销课记录，同时将销课数大于本销课数的所有销课数-1
							// 二、xiugaishuju中添加删除销课的记录，
							// 三、baokelist中已核销数减1
							uniCloud.callFunction({
								name:"xinhuiyuan",
								data:{
									leixing:5,//类型为5时，调出这个学生的销课记录
									id:e._id,
									baokeid:e.baokeid,
									detail:"删除"+e.name+"【"+e.kecheng+"】的销课记录，销课时间："+e.xiaoketime,
									xiaoqu:e.xiaoqu,
									yihexiaoshu:e.yihexiaoshu,
									riqi:getDateTime.dateTimeStr('y-m-d h:i:s'),
									jingshouren:this.jingshouren,
									baokeid:e.baokeid
								}
							}).then(res1=>{
								this.xueshenginfo(e.baokeid)
								uni.hideLoading();
							})
						}
					},
					fail: () => {},
					complete: () => {}
				});
			},
			// 学生信息的数据库调取
			async xueshenginfo(e) {
				await this.xiaokelist(e)
				uni.showLoading({
					title: '学生信息获取中……',
					mask: true
				});
				uniCloud.callFunction({
					name:"xinhuiyuan",
					data:{
						leixing:2,//类型为5时，调出这个学生的销课记录
						_id:e
					}
				}).then(res=>{
					this.infor=res.result.data[0]
					this.infor1=res.result.data[0].id[0]
					this.infor.xiaokeshu=this.shu1
					uni.setStorageSync('aoyashenginfor',this.infor)
					uni.hideLoading()
				})
			},	
			// 销课记录的数据库调取
			xiaokelist(e) {
				uni.showLoading({
					title: '销课信息获取中……',
					mask: true
				});
				uniCloud.callFunction({
					name:"funshare",
					data:{
						leixing:5,//类型为5时，调出这个学生的销课记录
						baokeid:e
					}
				}).then(res=>{
					this.shu2=res.result.data//本人的销课列表
					this.shu1=res.result.data.length
					uni.hideLoading()
				})
				},
		}
	}
</script>

<style>

</style>
